﻿using MediatR;
using MS.BasicData.Infrastructure;
using MS.BasicData.Infrastructure.BaseRepository;
using System.ComponentModel.DataAnnotations;

namespace MS.BasicData.Read.API.Applications.ProductInfos
{
    public class ListProductInfoRequestHandler : IRequestHandler<ListProductInfoRequestModel, ApiRestult>
    {
        private readonly IProductInfoBaseRepository _productInfoBaseRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productInfoBaseRepository"></param>
        public ListProductInfoRequestHandler(IProductInfoBaseRepository productInfoBaseRepository)
        {
            _productInfoBaseRepository = productInfoBaseRepository;
        }

        public async Task<ApiRestult> Handle(ListProductInfoRequestModel request, CancellationToken cancellationToken)
        {
            ApiRestult restult = new ApiRestult
            {
                isSuc = true,
                Code = Restult.Success,
                Message = "商品信息获取成功"
            };
            var productlist = await _productInfoBaseRepository.GetAllAsync();
            restult.Data = productlist;
            return restult;
        }
    }


    public class ListProductInfoRequestModel : IRequest<ApiRestult> 
    {
    }
}
